package com.azkj.album.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.azkj.album.R;
import com.azkj.album.dto.NewGalleryBean;
import com.azkj.album.network.utils.LogUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

public class ClassPhotoAdapter extends BaseQuickAdapter<NewGalleryBean, BaseViewHolder> {
    private Context mContext;

    public ClassPhotoAdapter(Context context, int layoutResId) {
        super(layoutResId);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, NewGalleryBean item) {
        ImageView image = helper.getView(R.id.iv_image);
        ImageView image_dele = helper.getView(R.id.iv_image_dele);
        ProgressBar progressBar = helper.getView(R.id.progress);
        TextView tv_add_pic = helper.getView(R.id.tv_add_pic);
        image_dele.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                remove(helper.getAdapterPosition());
                notifyItemChanged(helper.getAdapterPosition());
            }
        });
        if (item.getImgPath().equals("add")) {
            Glide.with(mContext).load(R.mipmap.ic_add_photo).into(image);
            image_dele.setVisibility(View.GONE);
            progressBar.setVisibility(View.GONE);
            tv_add_pic.setVisibility(View.VISIBLE);
        } else {
            Glide.with(mContext).load(item.getImgPath()).into(image);
            image_dele.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(item.getFullUrl()) || 0 == item.getProgress()) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
            tv_add_pic.setVisibility(View.GONE);
        }
        LogUtils.e(item.getImgPath() + "-progress is-" + item.getProgress());
    }
}
